<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kafka 消息可靠性保障机制</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        /* 首字下沉效果 */
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #4f46e5;
            font-family: 'Noto Serif SC', serif;
        }
        
        /* 卡片悬停效果 */
        .card-hover {
            transition: all 0.3s ease;
            cursor: pointer;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        
        /* 渐变文字效果 */
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        /* 数字标记样式 */
        .number-badge {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 2rem;
            height: 2rem;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            font-weight: 700;
            margin-right: 0.75rem;
            flex-shrink: 0;
        }
        
        /* 图片容器样式 */
        .image-container {
            position: relative;
            overflow: hidden;
            border-radius: 0.75rem;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
        }
        
        .image-container img {
            transition: transform 0.3s ease;
        }
        
        .image-container:hover img {
            transform: scale(1.05);
        }
        
        /* 滚动动画 */
        .fade-in {
            opacity: 0;
            transform: translateY(20px);
            transition: all 0.6s ease;
        }
        
        .fade-in.visible {
            opacity: 1;
            transform: translateY(0);
        }
        
        /* Mermaid 图表样式 */
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 0.75rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body>
    <!-- Hero 区域 -->
    <section class="relative overflow-hidden bg-gradient-to-br from-indigo-600 via-purple-600 to-pink-500 text-white">
        <div class="absolute inset-0 bg-black opacity-20"></div>
        <div class="relative max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-24 lg:py-32">
            <div class="text-center">
                <h1 class="text-5xl lg:text-7xl font-bold mb-6 tracking-tight">
                    <span class="block">Kafka</span>
                    <span class="block text-3xl lg:text-5xl mt-2 font-light opacity-90">消息可靠性保障机制</span>
                </h1>
                <p class="text-xl lg:text-2xl max-w-3xl mx-auto opacity-90 leading-relaxed">
                    深入解析 Apache Kafka 如何通过分布式架构和副本机制，确保消息在各种故障场景下的可靠传递
                </p>
                <div class="mt-10 flex justify-center space-x-4">
                    <div class="flex items-center space-x-2 bg-white bg-opacity-20 rounded-full px-6 py-3">
                        <i class="fas fa-shield-alt"></i>
                        <span>高可靠性</span>
                    </div>
                    <div class="flex items-center space-x-2 bg-white bg-opacity-20 rounded-full px-6 py-3">
                        <i class="fas fa-sync-alt"></i>
                        <span>分布式架构</span>
                    </div>
                    <div class="flex items-center space-x-2 bg-white bg-opacity-20 rounded-full px-6 py-3">
                        <i class="fas fa-database"></i>
                        <span>持久化存储</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="absolute bottom-0 left-0 right-0">
            <svg viewBox="0 0 1440 120" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M0 120L60 105C120 90 240 60 360 45C480 30 600 30 720 37.5C840 45 960 60 1080 67.5C1200 75 1320 75 1380 75L1440 75V120H1380C1320 120 1200 120 1080 120C960 120 840 120 720 120C600 120 480 120 360 120C240 120 120 120 60 120H0Z" fill="white"/>
            </svg>
        </div>
    </section>

    <!-- 主要内容区域 -->
    <main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- 引言 -->
        <section class="mb-16 fade-in">
            <div class="bg-white rounded-2xl shadow-xl p-8 lg:p-12">
                <p class="text-lg leading-relaxed text-gray-700 drop-cap">
                    Kafka保障消息可靠性的关键在于其分布式架构和副本机制。在 Kafka 中，消息可靠性主要通过以下方式来保障。
                </p>
            </div>
        </section>

        <!-- 核心机制概览 -->
        <section class="mb-16 fade-in">
            <h2 class="text-3xl font-bold mb-8 text-center gradient-text">核心保障机制</h2>
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="text-4xl text-indigo-600 mb-4">
                        <i class="fas fa-paper-plane"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">生产者发送</h3>
                    <p class="text-gray-600">确保消息可靠发送，支持多种确认机制</p>
                </div>
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="text-4xl text-purple-600 mb-4">
                        <i class="fas fa-copy"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">消息复制</h3>
                    <p class="text-gray-600">通过副本机制保证数据冗余和高可用</p>
                </div>
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="text-4xl text-pink-600 mb-4">
                        <i class="fas fa-exchange-alt"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2">故障转移</h3>
                    <p class="text-gray-600">自动选举新Leader，保证服务连续性</p>
                </div>
            </div>
        </section>

        <!-- 生产者发送消息 -->
        <section class="mb-16 fade-in">
            <div class="bg-gradient-to-r from-indigo-50 to-purple-50 rounded-2xl p-8 lg:p-12">
                <h2 class="text-3xl font-bold mb-6 flex items-center">
                    <i class="fas fa-paper-plane mr-4 text-indigo-600"></i>
                    生产者发送消息
                </h2>
                <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                    Kafka生产者可以确保消息的可靠发送，并且在面对网络故障或者Kafka Broker的不可用情况下，依然能够保持消息的可靠性和一致性。
                </p>
                
                <div class="image-container mb-8">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1710054058229-44e6d9f1-c613-483f-83ee-f9a7d5179a3c.png" alt="生产者发送消息" class="w-full">
                </div>

                <div class="space-y-4">
                    <div class="flex items-start bg-white rounded-lg p-4 shadow">
                        <span class="number-badge">1</span>
                        <div>
                            <h4 class="font-bold text-lg mb-1">消息持久化</h4>
                            <p class="text-gray-600">生产者发送的消息首先被写入到Kafka Broker的内存中，然后异步地写入到磁盘中，确保消息不会因为内存中的数据丢失而丢失。</p>
                        </div>
                    </div>
                    <div class="flex items-start bg-white rounded-lg p-4 shadow">
                        <span class="number-badge">2</span>
                        <div>
                            <h4 class="font-bold text-lg mb-1">批量发送</h4>
                            <p class="text-gray-600">生产者可以配置批量发送消息的大小和时间间隔，以减少网络开销和提高效率。</p>
                        </div>
                    </div>
                    <div class="flex items-start bg-white rounded-lg p-4 shadow">
                        <span class="number-badge">3</span>
                        <div>
                            <h4 class="font-bold text-lg mb-1">消息确认机制</h4>
                            <p class="text-gray-600">生产者可以选择消息的确认机制。有三种机制可供选择：acks=0（生产者不会等待任何确认，将消息发送到Kafka就算完成）、acks=1（leader收到消息后即向生产者发送确认）、acks=all（leader和所有副本都确认消息后，生产者才会收到确认）。</p>
                        </div>
                    </div>
                    <div class="flex items-start bg-white rounded-lg p-4 shadow">
                        <span class="number-badge">4</span>
                        <div>
                            <h4 class="font-bold text-lg mb-1">重试机制</h4>
                            <p class="text-gray-600">如果发送消息失败，生产者可以选择重试发送，直到收到确认或者达到重试次数上限为止。</p>
                        </div>
                    </div>
                    <div class="flex items-start bg-white rounded-lg p-4 shadow">
                        <span class="number-badge">5</span>
                        <div>
                            <h4 class="font-bold text-lg mb-1">失败处理</h4>
                            <p class="text-gray-600">生产者可以通过配置失败处理策略来处理发送失败的消息，比如重试、丢弃、或者自定义处理逻辑。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 消息复制 -->
        <section class="mb-16 fade-in">
            <div class="bg-gradient-to-r from-purple-50 to-pink-50 rounded-2xl p-8 lg:p-12">
                <h2 class="text-3xl font-bold mb-6 flex items-center">
                    <i class="fas fa-copy mr-4 text-purple-600"></i>
                    消息复制
                </h2>
                <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                    Kafka使用副本机制来复制消息，确保即使某个Broker发生故障，消息仍然可以被可靠地获取。通过消息复制机制，Kafka保证了消息的可靠性和持久性，即使在出现 Broker 故障或网络分区的情况下，也能保证消息的可靠传递和持久存储。
                </p>
                
                <div class="image-container mb-8">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1710054100125-b0686361-610b-4343-b694-e90ce0d28a14.png" alt="消息复制" class="w-full">
                </div>

                <div class="grid grid-cols-1 lg:grid-